/*
 * JEDHelp.java
 *
 * Created on June 1, 2002, 8:24 AM
 */

package driver.ted;
import javax.swing.text.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.net.URL;



/**
 *
 * @author  tdriver
 */
public class JEDHelp extends javax.swing.JFrame {

    boolean shouldDisplay = true;
    
    /** Creates new form JEDHelp */
    public JEDHelp() {
        initComponents();
        openAndLoadFile();
        jEditorPane1.addHyperlinkListener(new HyperlinkListener (){
            public void hyperlinkUpdate(HyperlinkEvent e) {
  	          if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
  		      JEditorPane pane = (JEditorPane) e.getSource();
  		      try {
  			   pane.setPage(e.getURL());
  		      } catch (Throwable t) {
  			   t.printStackTrace();
  		      }
  		   }
  	          }
            });
            if(shouldDisplay)
                setVisible(true);
            else
                dispose();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        jScrollPane1 = new javax.swing.JScrollPane();
        jEditorPane1 = new javax.swing.JEditorPane();

        setTitle("Jed Help");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        jScrollPane1.setBorder(null);
        jEditorPane1.setEditable(false);
        jScrollPane1.setViewportView(jEditorPane1);

        getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);

        pack();
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setSize(new java.awt.Dimension(800, 600));
        setLocation((screenSize.width-800)/2,(screenSize.height-600)/2);
    }//GEN-END:initComponents

    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
        // nothing
    }//GEN-LAST:event_exitForm
 public void openAndLoadFile(){
      // create the URL for the help file
    String s = null;
    try {
        s = "file:"
            + System.getProperty("user.dir") // this needs to be changed to reflect the constant install path of the help files (use registry)
            + System.getProperty("file.separator")
            + "jedhelp\\jedHelp.htm";
        URL helpURL = new URL(s);
        // set the page for the editor pane
         try {
              jEditorPane1.setPage(helpURL);
             } catch (IOException e) {
                javax.swing.JOptionPane.showMessageDialog(this,
                          "Attempted to read a bad URL: " + helpURL,
                          "IO Exception",
                          javax.swing.JOptionPane.ERROR_MESSAGE);
                shouldDisplay = false;
             }
        } catch (Exception e) {
            javax.swing.JOptionPane.showMessageDialog(this,
                "Couldn't create help URL: " + s,
                "Exception",
                javax.swing.JOptionPane.ERROR_MESSAGE);    
                shouldDisplay = false;
        }
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JEditorPane jEditorPane1;
    // End of variables declaration//GEN-END:variables

}
